var ns;
var app = new Vue({
    el: '#app',
    data: {
        chatlist: [],
        ThreadType:1,//1--我的列表，3--我的收藏
        otherStatus:1,//1--已发布0--审核中

        ThreadStatus: 1,
        is_searching: true,
        is_active:false,
        isShow:false,//是否打开菜单
    },
    methods: {
        get_data: function() {
            var that = this;
            var options = {};
            options.action = 'deleteblacks';
            // if(that.ThreadType==1){
            //     options.ThreadType = that.ThreadType;
            //     options.ThreadStatus = that.ThreadStatus;
            // }
            // if(that.ThreadType==3){
            //     options.ThreadType = that.ThreadType;
            //     options.ThreadStatus = that.otherStatus;
            // }
            // options.top = '9999';
            // options.type = 1;
            ns.post(options, function(succeed, data, err) { 
                console.log(JSON.stringify(options));
                console.log(JSON.stringify(data));
                that.is_searching = false;
                if (succeed) {
                    that.chatlist = data.chatlist;
                    // setTimeout(function() {
                    //     that.menuFixed('top_menus');
                    // }, 200)
                }
            });
        },
        check_post_status: function(callback, title, name, id) {
            ns.post({
                action: 'checkuserpostthreadstatus',
            }, function(succeed, data, err) {
                if (succeed) {
                    if (typeof callback == "function") {
                        callback.call(this, title, name, id);
                    }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        // do_collectposts
        open_win: function(title, name, id, checkpost) {
            var that = this;
            if (name == '') {
                return;
            }
            id = id || 0;
            if (checkpost) {
                that.check_post_status(that.open_win, title, name, id);
                return;
            }
            ns.openWin(name, title, {
                title: title,
                url: name + '.html',
                id: id
            }, {
                needlogin: true
            });
        },
        // menuFixed: function(id) {
        //     var that = this;
        //     var obj = document.getElementById(id);
        //     var height = obj.offsetTop;
        //     window.onscroll = function() {
        //         var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        //         var page_width = document.documentElement.offsetWidth || document.body.offsetWidth;
        //         if (scrollTop <= height) {
        //             obj.style.position = 'static';
        //             obj.style.left = 0;
        //             obj.style.right = 0;
        //             obj.style.width = '100%';
        //         } else {
        //             obj.style.position = 'fixed';
        //             obj.style.top = 0;
        //             obj.style.left = '10px';
        //             obj.style.right = '10px';
        //             obj.style.width = (page_width - 20) + 'px';
        //         }
        //     }
        // },

        do_praise: function(item) {
            var that = this;
            that.do_post_thread(item);
        },
        do_post_thread: function(item) {
            var that = this;
            ns.post({
                id: item.id,
                action: 'postthreadpraise'
            }, function(succeed, data, err) {
                if (succeed) {
                    item.ispraised = data.IsPraise;
                    item.praisecount = data.count;
                    item.praisecountdesc = data.count;
                    
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        do_quxiao:function(id){
            var that=this;
            ns.post({
                id:id,
                action: 'updatethread'
            }, function(succeed, data, err) {
                if (succeed) {
                    api.toast({
                        msg: '提交成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    that.get_data();
                    
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });


        },
        do_delete:function(id){
            var that=this;
            ns.post({
                id:id,
                action: 'removethreapost'
            }, function(succeed, data, err) {
                if (succeed) {
                    api.toast({
                        msg: '提交成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    that.get_data();
                    
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });


        },


    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.ThreadType = api.pageParam.ThreadType;
    app.otherStatus = api.pageParam.ThreadStatus;
    app.get_data();
    api.addEventListener({
        name: 'open_menus_input'
    }, function(ret, err) {
        if (ret) {
            app.isShow=!app.isShow;
        }
    });
};
